package com.wxy.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxy.domain.UserBookNum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

/**
 * @author 47868
 */
@Mapper
@Component("UserBookDao")
public interface UserBookDao extends BaseMapper<UserBookNum> {
    /**
     * 更新用户可借阅书籍剩余数量
     * @param uid 用户id
     */
    @Update("update userbooknum set nums=nums-1 where uid=#{uid}")
    void deleteOneNumByUid(Long uid);

    /**
     * 更新用户可借阅书籍剩余数量
     * @param uid 用户id
     */
    @Update("update userbooknum set nums=nums+1 where uid=#{uid}")
    void plusOneNumsByUid(Long uid);

    /**
     * 查询用户剩余可借阅书籍数量
     * @param uid 用户id
     * @return 剩余数量
     */
    @Select("select nums from userbooknum where uid=#{uid}")
    int getNumByUid(Long uid);
}
